import axios from 'axios';

// 创建axios实例
const instance = axios.create({
  baseURL: 'https://api.example.com', // 设置基础URL
  timeout: 5000, // 超时时间
});

/**
 * 封装GET请求
 *
 * @param url url
 * @param params 请求参数
 */
export const get = async (url, params) => {
  try {
    const response = await instance.get(url, { params });
    return response.data;
  } catch (error) {
    console.error('GET请求出错:', error);
    throw error;
  }
};


/**
 * 封装POST请求
 *
 * @param url url
 * @param data 请求数据
 */

export const post = async (url, data) => {
  try {
    const response = await instance.post(url, data);
    return response.data;
  } catch (error) {
    console.error('POST请求出错:', error);
    throw error;
  }
};
